import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:zootix/models/zt_ticket.model.dart';
import 'package:zootix/store/zt_store.dart';
import 'package:zootix/util/zt_common.util.dart';
import 'package:zootix/util/zt_screen_adaper_util.dart';
import 'package:zootix/widgets/zt_empty.dart';

class ZtMineMyTickets extends StatelessWidget {
  const ZtMineMyTickets({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(
      () => ZtTicketStore.to.myTicketList.isEmpty
          ? ZtEmpty()
          : SingleChildScrollView(
              child: Column(
              children: [
                SizedBox(
                  height: ZtScreenAdaper.height(10),
                ),
                ...ZtTicketStore.to.myTicketList
                    .map((element) => _buildTicketCartItem(element))
                    .toList()
              ],
            )),
    );
  }

  Widget _buildTicketCartItem(ZtTicketModel item) {
    return Stack(
      children: [
        Container(
          margin: EdgeInsets.symmetric(
              vertical: ZtScreenAdaper.height(10),
              horizontal: ZtScreenAdaper.width(20)),
          padding: EdgeInsets.symmetric(
              horizontal: ZtScreenAdaper.width(30),
              vertical: ZtScreenAdaper.height(15)),
          decoration: BoxDecoration(
              borderRadius:
                  BorderRadius.all(Radius.circular(ZtScreenAdaper.sp(15))),
              border: Border.all(color: const Color(0xFFFFDA7B))),
          child: Row(children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '${ZtCommonUtil.firstUppercase(item.parkType)} ticket',
                  style: TextStyle(
                      color: const Color(0xFF404040),
                      fontSize: ZtScreenAdaper.sp(20),
                      fontWeight: FontWeight.w500),
                ),
                SizedBox(
                  height: ZtScreenAdaper.height(5),
                ),
                Text(
                  item.ticketNumber,
                  style: TextStyle(
                      color: const Color(0xFFF3AA3B),
                      fontSize: ZtScreenAdaper.sp(16)),
                )
              ],
            ),
            const Spacer(),
            ElevatedButton(
                style: ElevatedButton.styleFrom(
                    shape: RoundedRectangleBorder(
                        borderRadius:
                            BorderRadius.circular(ZtScreenAdaper.sp(30))),
                    padding: EdgeInsets.symmetric(
                        horizontal: ZtScreenAdaper.height(30),
                        vertical: ZtScreenAdaper.height(5)),
                    backgroundColor: const Color(0xFFFFCA41)),
                onPressed: () {
                  ZtCommonUtil.doCopy(item.ticketNumber);
                },
                child: Text(
                  'Copy',
                  style: TextStyle(fontSize: ZtScreenAdaper.sp(18)),
                ))
          ]),
        ),
        Positioned(
            top: ZtScreenAdaper.height(5),
            right: ZtScreenAdaper.width(10),
            child: Container(
              alignment: Alignment.center,
              decoration: BoxDecoration(
                  color: const Color(0xFFFFF2D0),
                  borderRadius: BorderRadius.circular(ZtScreenAdaper.sp(2))),
              height: ZtScreenAdaper.height(20),
              width: ZtScreenAdaper.width(80),
              child: Text(
                'To be used',
                style: TextStyle(
                  fontSize: ZtScreenAdaper.sp(13),
                  color: const Color(0xFFD69D0C),
                ),
              ),
            ))
      ],
    );
  }
}
